package com.neusoft.hifly.lock.utils;

import java.util.Iterator;
import java.util.Map;

/**
 * Redis 常量
 */
public final class RedisContent {
	/**
	 * key之间的分隔符
	 */
	public static final String S = ":";

	/**
	 * 删除key下全部数据
	 */
	public static final String DEL_ALL = "*";

	// ###################################################

	/**
	 * 底层平台redis key开头
	 */
	public static final String KEY_SAAS = "saas";

	/**
	 * 租户平台redis key开头
	 */
	public static final String KEY_S = "s";

	// ###################################################
	/**
	 * 将MAP的KEY转化为string
	 *
	 * @param property
	 *            参数。其中isLike:Boolean 是否模糊查询
	 * @return KEY转化为string
	 */
	public static String mapKeyToStr(final Map<String, Object> property) {
		if (property == null) {
			return null;
		}
		final StringBuffer sb = new StringBuffer("");
		final Iterator<Map.Entry<String, Object>> iter = property.entrySet().iterator();
		while (iter.hasNext()) {
			final Map.Entry<String, Object> entry = iter.next();
			final String key = entry.getKey();
			final Object val = entry.getValue();

			sb.append(key + RedisContent.S + String.valueOf(val) + RedisContent.S);
		}

		sb.delete(sb.length() - 1, sb.length());
		return sb.toString();
	}

	/**
	 * 将MAP的KEY转化为string
	 *
	 * @param offset
	 *            当前页数
	 * @param limit
	 *            分页长度
	 * @param property
	 *            参数。其中isLike:Boolean 是否模糊查询
	 * @return KEY转化为string
	 */
	public static String mapKeyToStr(final int offset, final int limit, final Map<String, Object> property) {
		final StringBuffer sb = new StringBuffer("");
		if (property != null) {
			final Iterator<Map.Entry<String, Object>> iter = property.entrySet().iterator();
			while (iter.hasNext()) {
				final Map.Entry<String, Object> entry = iter.next();
				final String key = entry.getKey();
				final Object val = entry.getValue();

				sb.append(key + RedisContent.S + String.valueOf(val) + RedisContent.S);
			}

		}
		// 把分页放到后面
		sb.append(offset + "_" + limit);
		return sb.toString();
	}
}
